//
//  MCMallStatisticsCell.swift
//  StoreManage
//
//  Created by MC on 2018/9/3.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit


class MCMallStatisticsCell: UITableViewCell {
    
    
    var model = MCOrderListModel() {
        didSet {
            iconImageView.sd_setImage(with: URL.init(string: model.navigateImg1), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
            
            if model.goodName.count == 0 {
                nameLabel.text = model.goodsName
            } else {
                nameLabel.text = model.goodName + model.goodName + model.goodName
            }
            
            commissionView.rightLabel.text = MCString_judgemantDecimalsIsZero(figure: model.fee.intValue)
            moneyLabel.text = MCString_judgemantDecimalsIsZero(figure: model.salePrice)
            specLabel.text = model.specName
            numberLabel.text = "x" + String(model.quantity)
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        backgroundColor = UIColor.white
        
        self.addSubview(bgView)
        bgView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(0, 0, 2, 0))
        }
        
        bgView.addSubview(iconImageView)
        iconImageView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(bgView).offset(15)
            make.top.equalTo(10)
            make.size.equalTo(CGSize.init(width: 80, height: 80))
        }
        
        iconImageView.addSubview(signImageView)
        signImageView.snp.remakeConstraints { (make) ->Void in
            make.left.top.equalTo(iconImageView)
            make.size.equalTo(CGSize.init(width: 30, height: 30))
        }
        
        
        bgView.addSubview(numberLabel)
        numberLabel.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(bgView).offset(-15)
            make.bottom.equalTo(iconImageView).offset(-2)
            make.width.equalTo(40)
            make.height.equalTo(20)
        }
        
        bgView.addSubview(moneyLabel)
        moneyLabel.snp.remakeConstraints { (make) ->Void in
            make.bottom.equalTo(iconImageView)
            make.left.equalTo(iconImageView.snp.right).offset(10)
        }
        
        
        bgView.addSubview(specLabel)
        specLabel.snp.remakeConstraints { (make) ->Void in
            make.bottom.equalTo(moneyLabel.snp.top).offset(-3)
            make.left.equalTo(iconImageView.snp.right).offset(10)
            make.right.equalTo(numberLabel.snp.left).offset(-10)
        }
        
        
        bgView.addSubview(nameLabel)
        nameLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(iconImageView.snp.right).offset(5)
            make.right.equalTo(bgView).offset(-10)
            make.top.equalTo(iconImageView).offset(2)
            make.bottom.lessThanOrEqualTo(specLabel.snp.top).offset(-4)
        }
        
        bgView.addSubview(commissionView)
        commissionView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(iconImageView).offset(2)
            make.right.equalTo(numberLabel)
            make.top.equalTo(iconImageView.snp.bottom)
            make.height.equalTo(40)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_light
        return view
    }()
    
    lazy var iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.borderColor = UIColor.white.cgColor
        imageView.layer.borderWidth = 1
        imageView.image = #imageLiteral(resourceName: "Reuse_placeholder_1_1")
        return imageView
    }()
    
    lazy var signImageView: UIImageView = {
        let imageView = UIImageView()
        return imageView
    }()
    
    
    public lazy var nameLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(14)
        label.textColor = UIColor.MCBlack
        label.numberOfLines = 0
        return label
    }()
    
    
    public lazy var specLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(12)
        label.textColor = UIColor.MCGray_middle
        return label
    }()
    
    public lazy var numberLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(14)
        label.textColor = UIColor.MCBlack
        label.textAlignment = NSTextAlignment.right
        return label
    }()
    
    public lazy var moneyLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(14)
        label.textColor = UIColor.MCBlack
        return label
    }()
    
    lazy var commissionView: MCShowBarView = {
        let view = MCShowBarView()
        view.leftLabel.text = "佣金"
        view.rightLabel.text = "¥333"
        view.lineView.isHidden = true
        return view
    }()
    
    
}
